package ch8recursion;

import java.util.ArrayList;
import java.util.Arrays;

public class Ex3 {

	@SuppressWarnings("unchecked")
	static ArrayList<ArrayList<Integer>> getSubsets(ArrayList<Integer> set) {
		ArrayList<ArrayList<Integer>> result = new ArrayList<>();
		if (set.size() == 0) {
			result.add(new ArrayList<Integer>());
		} else {
			Integer head = set.get(0);
			ArrayList<Integer> subset = (ArrayList<Integer>) set.clone();
			subset.remove(0);
			ArrayList<ArrayList<Integer>> subResult = getSubsets(subset);
			for (ArrayList<Integer> partial : subResult) {
				result.add((ArrayList<Integer>) partial.clone());
				partial.add(0, head);
			}
			result.addAll(subResult);
		}
		return result;
	}

	public static void main(String... strings) {
		ArrayList<Integer> set = new ArrayList<>(Arrays.asList(new Integer[] {
				1, 2, 3 }));
		ArrayList<ArrayList<Integer>> subsets = getSubsets(set);
		int a = 0;
	}
}
